module ViewHelper

  def upload_picture(company)
    if session[:user_id]==company.user_id
      link_to "上传图片", {:controller=>'view', :action => 'uploadpic',:id=>company.picture_id,:object=>company.id},:popup=>['上传图片','height=400,width=350'],:id=>"mylink"
    else
      link_to "我来挑错", {}
    end
  end
  
  def commentdel_tag(comment)
    if session[:user_id]==comment.user_id
       link_to_remote("修改",:url=>{:controller=>"view", :action=>"modifycomment", :id=>comment.id},:update =>"mycomment") + "&nbsp;|&nbsp;"+ link_to_remote("删除",:url=>{:controller=>"view", :action=>"deletecomment", :id=>comment.id},:update =>"mycomment", :confirm => "确定删除吗?", :complete => "new Effect.Puff('comment#{comment.id}')")
    end
  end
  
  def commentpic_tag(comment)
    if comment.user_id==0
      '<img src=' + url_for(:controller=>"index",:action=>"postpicture",:id=> 1)+ ' width="60*60"/>'
    else
      '<img src=' + url_for(:controller=>"index",:action=>"postpicture",:id=> comment.User.picture_id)+ ' width="60*60"/>' 
    end
  end
  
  def viewuser_menu(user)
    if user.is_friend(session[:user_id])
      link_to "察看样本", :controller=>"report", :action=>"listuserincumbent", :id=>@user.id
    elsif session[:user_id]==user.id
      link_to "账户管理", :controller=>"view", :action=>"view"
    else
      link_to "加为好友", :controller=>"view", :action=>"createfriend", :id=>@user.id
    end
  end
  
  def commentuser_tag(comment)
    if comment.user_id==0
      "未登陆用户"
    elsif comment.User.anonymous==true
      link_to "匿名用户", :controller=>"view", :action=>"viewuser", :id=>comment.User.id
    else
      link_to h(comment.User.name), :controller=>"view", :action=>"viewuser", :id=>comment.User.id
    end
  end
  
  def commenttitle_tag(object)
    if object.class==Company
      text_field 'comment', 'title', :value=>"Re:"+object.cname, :style=>"width:300px"
    else
      text_field 'comment', 'title', :value=>"Re:"+object.title, :style=>"width:300px"
    end
  end
end
